package org.zfes.snowier.zbss.xzy.router.agreement;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.agreement.model.Agreement;
import org.zfes.snowier.zbss.xzy.biz.agreement.service.IAgreementService;
import org.zfes.snowier.core.data.SelectVo;
@Controller("org.zfes.snowier.zbss.xzy.router.agreement.AgreementController")
@RequestMapping("/manager/agreement")
public class AgreementController implements BaseController {

	
	@Autowired
	private IAgreementService agreementService;
	
	//@RequiresPermissions(value="agreement:loadAgreementDataSet",desc="协议列表")
    @RequestMapping(value="/loadAgreementDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAgreementDataSet(@RequestBody Map<String,Object> params){
	    DataSet dataSet=  agreementService.loadAgreementDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="agreement:createAgreement",desc="协议添加")
    @RequestMapping(value="/createAgreement", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object createAgreement(@RequestBody Agreement agreement){
		agreementService.createAgreement(agreement);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="agreement:loadAgreement",desc="协议加载")
    @RequestMapping(value="/loadAgreement/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAgreement(@PathVariable("id")Long id){
		Optional<Agreement> ops = agreementService.loadAgreementById(id);
		return ajaxQuery("agreement",ops);
    }
	
	//@RequiresPermissions(value="agreement:updateAgreement",desc="协议更新")
    @RequestMapping(value="/updateAgreement", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object updateAgreement(@RequestBody  Agreement agreement){
		agreementService.updateAgreement(agreement);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="agreement:deletAgreement",desc="协议删除")
    @RequestMapping(value="/deleteAgreement/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object deleteAgreement(@PathVariable("id")Long id){
		agreementService.deleteAgreement(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }


    @RequestMapping(value="/loadAgreementSelectVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAgreementSelectVo(){
		 List<SelectVo>  ops = agreementService.loadAgreementSelectVo("");
		return ajaxQuery("selectVo",ops);
    }
    
}